/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "pch.h"
#include "编译错误信息.h"
#include "结构代码解析.h"
#include "函数代码解析.h"
#include "变量代码解析.h"
#include "块代码解析.h"

#include <set>


void f_结构代码块解析(std::vector<std::u16string>::iterator& it
    , std::vector<std::u16string>::iterator& end
    , S_结构代码块& 结构代码
    , std::set<std::u16string>& 以声明类型
    ) {

    结构代码.结构名称 = *it;

    auto 结构实现 = f_括号域(it, end, u"{", u"}");
    auto vEnd = 结构实现.end();
    for(auto vIt = 结构实现.begin(); vIt != vEnd; ) {
        S_变量代码块* 变量代码块 = new S_变量代码块;
        f_变量代码块解析(vIt, vEnd, *变量代码块);

        if(以声明类型.find(变量代码块->类型名称) == 以声明类型.end()){
            结构代码.成员变量.push_back(变量代码块);
        }
        else{
			f_comInfo_输出错误(u"编译错误:结构类型以声明" + 变量代码块->类型名称);
            delete 变量代码块;
        }
    }
}


void f_虚函数代码解析(std::vector<std::u16string>::iterator& it
                    , std::vector<std::u16string>::iterator& end
                    , S_虚函数代码块& 虚函数代码) {

    虚函数代码.表名称 = *it;
    ++it;

    if(*it == u"{") {
        auto 函数声明 = f_括号域(it, end, u"{", u"}");
        
        auto vit = 函数声明.begin();
        auto vend = 函数声明.end();
        
        while(true){
            auto 虚函数 = f_代码切片(vit, vend, u";");
            if(虚函数.empty()) break;

            auto mit = 虚函数.begin();
            auto mend = 虚函数.end();

            虚函数代码.函数声明.push_back(f_函数声明代码块解析(mit, mend));
        }
    }
    
    return;
}


void f_结构成员解析(S_结构代码块& 结构代码){
    for(auto& e : 结构代码.成员变量){
        auto it = e->初始表达式.begin();
        auto end = e->初始表达式.end();

        if(it != end){
            if(*it == u"="){

            } else {
                
            }
        }
    }
}


